7 public static String
clean(String s
){
10 for (int i
=0; i
<s
.length(); ++i
){
11 if (Character
.isLetter(s
.charAt(i
))){
15 if (r
.charAt(r
.length()-1) == 's'){
16 r
= r
.substring(0, r
.length()-1);
21 public void procesarCaso(ArrayList
<String
> p
, String s
){
22 HashMap
<String
, Character
> m
= new HashMap
<String
, Character
>();
23 String sufijos
[] = s
.split(" ");
25 boolean ilegal
= false;
26 char sufijoActual
= 'A';
27 for (int i
=0; i
<p
.size(); ++i
){
29 for (int j
=0; j
<sufijos
.length
; ++j
){
30 if (p
.get(i
).endsWith(sufijos
[j
])){
31 //System.out.println(p.get(i) + " rima con " + sufijos[j]);
33 if (m
.containsKey(sufijos
[j
])){
34 result
+= m
.get(sufijos
[j
]);
36 m
.put(sufijos
[j
], Character
.valueOf(sufijoActual
));
37 result
+= sufijoActual
;
47 //System.out.println(result);
50 System
.out
.println("Not a chance!");
53 if (result
.equals("ABBAABBACDECDE") || result
.equals("ABBAABBACDEDCE") || result
.equals("ABBAABBACDCDCD")){
54 System
.out
.println(result
);
57 System
.out
.println("Not a chance!");
61 public static void main(String
[] args
) throws IOException
{
63 BufferedReader reader
= new BufferedReader(new InputStreamReader(System
.in
));
64 String line
= reader
.readLine();
66 String sufijos
= line
;
67 line
= reader
.readLine();
68 System
.out
.print(line
+ ": "); //titulo
69 //ahora leamos el cuerpo del poema
70 line
= reader
.readLine();
71 ArrayList
<String
> p
= new ArrayList
<String
>();
72 while (line
!= null && line
.trim().length() > 0){
73 //System.out.println("Read " + line);
75 //System.out.println("Added " + p.get(p.size()-1));
76 line
= reader
.readLine();
79 s
.procesarCaso(p
, sufijos
);
81 line
= reader
.readLine(); //leer sufijos del siguiente caso